<?php
if (isset($_POST['meta_web_form_id'])) {

//preparazione email
$messaggio = "";
foreach ($_POST as $key => $value) {
	$key = (strpos($key, "custom") === false) ? $key : str_replace("_"," ",$key);
	if (strpos($key,"meta")===false && strpos($key,"submit")===false && strpos($key,"Privacy")===false && strpos($key,"redirect")===false && strpos($key,"unit")===false) 
		$messaggio .= $key.": ".$value."\n\n";
} 
$headers = 'From: Bsvillage<info@bsvillage.com>' . "\r\n" .	'Reply-To: info@bsvillage.com';
if ($_POST['from']!="") mail('marcello@bsvillage.com','BsVillage - '.$_POST['name'].' Prodotto: '.$_POST['nome_prodotto'],str_replace("&","\n",$messaggio)/*,$headers*/);

//inserimento dati in DB
function ControlloEmail($email){
	$result = eregi("^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$",$email);
	if($result == false){
		return false;
	}else{
		return true;
	}
}
//if ($_POST['email']!="" && ControlloEmail($_POST['email'])) mysql_query("insert into postDataAweber (data, nome, email, dati) values ('".time()."', '".$_POST['name']."', '".$_POST['email']."', '".$messaggio."')") or die ("Errore");

//form per dati ?>
<form id="form_post" name="form_post" method="post" action="http://www.aweber.com/scripts/addlead.pl">
    <?php
    foreach ($_POST as $key => $value) 
		if (strpos($key,"nome_prodotto")===false) {
			if (strpos($key,"submit")===false) {
				$nameInput = (substr($key,0,4)=="meta" || substr($key,0,4)=="url_") ? $key : str_replace("_", " ", $key);
				echo '<input type="hidden" name="'.$nameInput.'" value="'.$value.'" />'."\n";
			} else
				echo '<input type="hidden" id="submitAweberField" name="'.str_replace("_", " ", $key).'" value="'.$value.'" />'."\n";
		}
	?>
</form>
<script type="text/javascript">
	var submitAttributes=document.getElementById("submitAweberField").attributes;
	submitAttributes.getNamedItem("name").value = "submitAweber";
	
	document.getElementById("form_post").submit();
</script>

<?php
return;

} ?>